import {INPUT_CHANGE,BUTTON_CLICK,DEL_ITEM} from './ActionType.js'

const defaultState = {
    inputValue :'',
    list : [1,2]
}

export default (state = defaultState,action)=>{
    if (action.type === INPUT_CHANGE) {
        const newState = JSON.parse(JSON.stringify(state));
        newState.inputValue = action.value;
        return newState;
    }
    if (action.type === BUTTON_CLICK) {
        const newState = JSON.parse(JSON.stringify(state));
        newState.list.push(newState.inputValue);
        newState.inputValue = '';
        return newState;
    }
    if (action.type === DEL_ITEM) {
        const newState = JSON.parse(JSON.stringify(state));
        newState.list.splice(action.index,1);
        return newState;
    }

    return state;
}